#include "INCLUDE/VideoChild.h"
#include "../JWTS/INCLUDE/AnsiConverter.h"

#include <QMediaPlayer>

VideoChild::VideoChild(const char *p_file_name, QWidget* parent) :
    QVideoWidget(parent),
    MdiChild("VIDEOWINDOW")
{
    QMediaPlayer *mediaPlayer = new QMediaPlayer(this);
    mediaPlayer->setVideoOutput(this);
    mediaPlayer->setMedia(QUrl::fromLocalFile(toQtStr(p_file_name)));

    connect(this, &VideoChild::windowShown, mediaPlayer, &QMediaPlayer::play);

    setMinimumSize(parent->size()/8);

    setAttribute(Qt::WA_DeleteOnClose);
}

void VideoChild::closeEvent(QCloseEvent *event)
{
    emit pSignalEmitter()->aboutToClose(this);

    QVideoWidget::closeEvent(event);
}

void VideoChild::showEvent(QShowEvent *event)
{
    QVideoWidget::showEvent(event);

    emit windowShown();
}
